package com.sam.im.heiqun.uis.activities;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView;

import com.sam.im.heiqun.R;
import com.yuyh.library.utils.EventBusType;
import com.sam.im.heiqun.utils.ToolsUtils;
import com.yuyh.library.uis.activitys.BaseSwipeBackActivity;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;


/**
 * Created by wangguodong on 2017/9/6.
 */
public class LaboratoryLookActivity extends BaseSwipeBackActivity {

    @BindView(R.id.start_look)
    Switch start_look;
    @BindView(R.id.txt_title)
    TextView txt_title;
    @BindView(R.id.txt_content)
    TextView txt_content;
    @BindView(R.id.txt_swith)
    TextView txt_swith;
    @BindView(R.id.image_title)
    ImageView image_title;

    int type = 0 ;//0-看一看；1-搜一搜

    public static void start(Activity activity, int type ){
        Intent intent = new Intent(activity, LaboratoryLookActivity.class);
        intent.putExtra("type",type);
        activity.startActivity(intent);
    }

    @Override
    protected String getTitleText() {
        return getResources().getString(R.string.laboratory);
    }

    @Override
    protected void initViews(Bundle savedInstanceState) {

        type = getIntent().getIntExtra("type",0);
        if (0 == type){
            image_title.setBackgroundResource(R.drawable.laboratory_look);
            String isShowLook = ToolsUtils.saveLook(LaboratoryLookActivity.this,ToolsUtils.getMyUserId(),"1",2);
            if ("1".equals(isShowLook)){
                start_look.setChecked(true);
            }
        }else {
            image_title.setBackgroundResource(R.drawable.laboratory_search);
            txt_title.setText(getResources().getString(R.string.sou_sou));
            txt_content.setText(getResources().getString(R.string.goto_sousou));
            txt_swith.setText(getResources().getString(R.string.start_sou_sou));
            String isShowSearch = ToolsUtils.saveSearch(LaboratoryLookActivity.this,ToolsUtils.getMyUserId(),"1",2);
            if ("1".equals(isShowSearch)){
                start_look.setChecked(true);
            }
        }


        start_look.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    if (0 == type){
                        ToolsUtils.saveLook(LaboratoryLookActivity.this,ToolsUtils.getMyUserId(),"1",1);
                    }else {
                        ToolsUtils.saveSearch(LaboratoryLookActivity.this,ToolsUtils.getMyUserId(),"1",1);
                    }

                }else {
                    if (0 == type){
                        ToolsUtils.saveLook(LaboratoryLookActivity.this,ToolsUtils.getMyUserId(),"0",1);
                    }else {
                        ToolsUtils.saveSearch(LaboratoryLookActivity.this,ToolsUtils.getMyUserId(),"0",1);
                    }
                }
                EventBus.getDefault().post(EventBusType.REFRESH_FRAGMENT_FIND);
            }
        });

    }

    @Override
    public int getContentViewId() {
        return R.layout.activity_laboratory_look;
    }


    @OnClick({})
    public void onClick(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.pre_v_back:
                scrollToFinishActivity();
                break;
        }
    }

}
